<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box{
            width: 150px;
            margin: 200px auto;
        }
    </style>
</head>
<body>
<div class="box">
    <img onclick="off(this)" src="img/off.jpg">
</div>

</body>
<script>

    var i = 0
    function off(e) {
        if (i==0){
            e.src = 'img/on.jpg'
            i = 1
        }
        else {
            e.src = 'img/off.jpg'
            i = 0
        }
    }
</script>
</html>